﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using b7.Models;

namespace b7.Controllers
{ 
    public class SlideNewController : Controller
    {
        private b7Models db = new b7Models();

        //
        // GET: /SlideNew/

        public ViewResult Index()
        {
            var baiviets = db.BaiViets.Include(b => b.Member);
            return View(baiviets.ToList());
        }

        //
        // GET: /SlideNew/Details/5

        public ViewResult Details(int id)
        {
            BaiViet baiviet = db.BaiViets.Find(id);
            return View(baiviet);
        }

        //
        // GET: /SlideNew/Create

        public ActionResult Create()
        {
            ViewBag.MemberId = new SelectList(db.Members, "MemberId", "Role");
            return View();
        } 

        //
        // POST: /SlideNew/Create

        [HttpPost]
        public ActionResult Create(BaiViet baiviet)
        {
            if (ModelState.IsValid)
            {
                db.BaiViets.Add(baiviet);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.MemberId = new SelectList(db.Members, "MemberId", "Role", baiviet.MemberId);
            return View(baiviet);
        }
        
        //
        // GET: /SlideNew/Edit/5
 
        public ActionResult Edit(int id)
        {
            BaiViet baiviet = db.BaiViets.Find(id);
            ViewBag.MemberId = new SelectList(db.Members, "MemberId", "Role", baiviet.MemberId);
            return View(baiviet);
        }

        //
        // POST: /SlideNew/Edit/5

        [HttpPost]
        public ActionResult Edit(BaiViet baiviet)
        {
            if (ModelState.IsValid)
            {
                db.Entry(baiviet).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.MemberId = new SelectList(db.Members, "MemberId", "Role", baiviet.MemberId);
            return View(baiviet);
        }

        //
        // GET: /SlideNew/Delete/5
 
        public ActionResult Delete(int id)
        {
            BaiViet baiviet = db.BaiViets.Find(id);
            return View(baiviet);
        }

        //
        // POST: /SlideNew/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            BaiViet baiviet = db.BaiViets.Find(id);
            db.BaiViets.Remove(baiviet);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}